#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
    void duplicateZeros(vector<int>& arr) {
        int n_zero = 0;
        for (int i = 0; i < arr.size(); ++i) if (arr[i] == 0) n_zero++;

        for (int i = 0; i < n_zero; ++i) arr.push_back(0);
        int n = arr.size() - 1;

        for (int i = 0; i <= n; ++i)
        {
            if (arr[i] == 0)
            {
                for (int j = n; j > i; --j)
                {
                    arr[j] = arr[j - 1];
                }
                arr[i] = 0;
                ++i;
            }
        }

        for (int i = 0; i < n_zero; ++i) arr.pop_back();
    }
};

int main()
{
    vector<int> v = { 1, 0, 2, 3, 0, 4, 5, 0 };
    Solution().duplicateZeros(v);
	return 0;
}